﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.Encounters.CampaignBattleResult
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.Core;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.Encounters
{
  public class CampaignBattleResult
  {
    internal static void AutoGeneratedStaticCollectObjectsCampaignBattleResult(
      object o,
      List<object> collectedObjects)
    {
      ((CampaignBattleResult) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected virtual void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
    }

    internal static object AutoGeneratedGetMemberValuePlayerVictory(object o)
    {
      return (object) ((CampaignBattleResult) o).PlayerVictory;
    }

    internal static object AutoGeneratedGetMemberValuePlayerDefeat(object o)
    {
      return (object) ((CampaignBattleResult) o).PlayerDefeat;
    }

    internal static object AutoGeneratedGetMemberValueEnemyPulledBack(object o)
    {
      return (object) ((CampaignBattleResult) o).EnemyPulledBack;
    }

    internal static object AutoGeneratedGetMemberValueEnemyRetreated(object o)
    {
      return (object) ((CampaignBattleResult) o).EnemyRetreated;
    }

    [SaveableProperty(0)]
    public bool PlayerVictory { get; private set; }

    [SaveableProperty(1)]
    public bool PlayerDefeat { get; private set; }

    [SaveableProperty(2)]
    public bool EnemyPulledBack { get; private set; }

    [SaveableProperty(3)]
    public bool EnemyRetreated { get; private set; }

    public bool BattleResolved => this.PlayerVictory || this.PlayerDefeat;

    public static CampaignBattleResult GetResult(BattleState winnerSide, bool enemyRetreated = false)
    {
      if (PlayerEncounter.Current == null)
        return (CampaignBattleResult) null;
      CampaignBattleResult result = new CampaignBattleResult();
      if (winnerSide == BattleState.AttackerVictory && PlayerEncounter.Current.PlayerSide == BattleSideEnum.Attacker || winnerSide == BattleState.DefenderVictory && PlayerEncounter.Current.PlayerSide == BattleSideEnum.Defender)
        result.PlayerVictory = true;
      else if (winnerSide == BattleState.AttackerVictory && PlayerEncounter.Current.PlayerSide == BattleSideEnum.Defender || winnerSide == BattleState.DefenderVictory && PlayerEncounter.Current.PlayerSide == BattleSideEnum.Attacker)
        result.PlayerDefeat = true;
      else if (winnerSide == BattleState.DefenderPullBack && PlayerEncounter.Current.PlayerSide == BattleSideEnum.Attacker)
        result.EnemyPulledBack = true;
      result.EnemyRetreated = enemyRetreated;
      return result;
    }
  }
}
